package org.com.liurz.iresources.activiti.util;

import lombok.Data;

/**
 * @author liurz
 * @version V1.0
 * @Package org.com.liurz.iresources.activiti.util
 * @date 2021/9/30 20:34
 * @Copyright © 2020-2028
 */


@Data
public class ResponseResult<T> {

    private int code;

    private String msg;

    private T data;

    private ResponseResult(){}

    public ResponseResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private ResponseResult(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
    }

    private ResponseResult(ResultCode resultCode, T data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }

    public static <T> ResponseResult<T> success() {
        return new ResponseResult<>(ResultCode.SUCCESS);
    }

    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<>(ResultCode.SUCCESS, data);
    }

    public static <T> ResponseResult<T> error(ResultCode resultCode) {
        return new ResponseResult<>(resultCode);
    }

    public static <T> ResponseResult<T> error(String msg) {
        return new ResponseResult<>(ResultCode.FAIL.getCode(), msg);
    }
}

